<?php

namespace App\Http\Services;

use AlibabaCloud\Client\Request\Request;
use Aws\S3\Exception\S3Exception;
use Aws\S3\S3Client;

class MinioService
{
    public function putFile(Request $request)
    {
        $argv = $request['argv'];
        $USAGE = "\n" .
            "To run this example, supply the name of an S3 bucket and a file to\n" .
            "upload to it.\n" .
            "\n" .
            "Ex: php PutObject.php <bucketname> <filename>\n";

        if (count($argv) <= 2) {
            echo $USAGE;
            exit();
        }

        $bucket = $argv[1];
        $file_Path = $argv[2];
        $key = basename($argv[2]);

        try {
            //Create a S3Client
            $s3Client = new S3Client([
                'profile' => 'default',
                'region' => 'us-west-2',
                'version' => '2006-03-01'
            ]);
            $result = $s3Client->putObject([
                'Bucket' => $bucket,
                'Key' => $key,
                'SourceFile' => $file_Path,
            ]);
        } catch (S3Exception $e) {
            echo $e->getMessage() . "\n";
        }
    }
}
